use ${dirTemp}/compustat_quarterly_markups_final, clear

* Options
global tab_options_disp se r2 indicate("Additional controls = latq lev liq"  "2-digit industry FE = *naicsq2*" ) star(* 0.1 ** 0.05 *** 0.01) nocons nonumbers  label

global tab_options_out style(tex) type nostar replace se ar2  label nonumber alignment(c) nonotes indicate("Additional controls = latq lev liq" "2-digit industry FE = *naicsq2*" , label("Yes" "No"))  noconst subs("(mean) freq_avg3" "\multirow{2}{*}{\shortstack[l]{Price adjustment \\ frequency}}" "(mean) dur_avg3" "\multirow{2}{*}{\shortstack[l]{Implied price \\ duration}}") nofloat nogaps

* Sample
keep if date_q >= yq(2005,1) & date_q <= yq(2011,4)


* Table D.1
* ======================

preserve 
keep if baseline == 1
collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF "Baseline" 
label var lmarkup_AP "Accounting profits" 
label var lmarkup_UC "User cost approach"

* Panel (a)
* ============
est clear
qui eststo: reg lmarkup_PF dur_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_AP dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_UC dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)        

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD1a.tex, $tab_options_out

* Panel (b)
* ============
est clear
qui eststo: reg lmarkup_PF freq_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_AP freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_UC freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)        

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD1b.tex, $tab_options_out

restore


* From here on drop extreme stickiness
keep if freq_avg3 < 0.99


* Table 1
* ======================

preserve 
keep if baseline == 1
collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF "Baseline" 
label var lmarkup_AP "Accounting profits" 
label var lmarkup_UC "User cost approach"

* Panel (a)
* ============
est clear
qui eststo: reg lmarkup_PF dur_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_AP dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_UC dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)        

esttab *, $tab_options_disp

esttab using ${dirOutput}/Table1a.tex, $tab_options_out

* Panel (b)
* ============
est clear
qui eststo: reg lmarkup_PF freq_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_AP freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_UC freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)        

esttab *, $tab_options_disp

esttab using ${dirOutput}/Table1b.tex, $tab_options_out

restore


* Table D.2
* ======================

preserve 
keep if baseline == 1
collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF_TL "4d Translog" 
label var lmarkup_PF_CS "4d cost shares" 
label var lmarkup_PF_sga "Baseline incl. SGA"

* Panel (a)
* ============
est clear
qui eststo: reg lmarkup_PF_TL  dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_CS  dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_sga dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)        

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD2a.tex, $tab_options_out

* Panel (b)
* ============
est clear
qui eststo: reg lmarkup_PF_TL  freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_CS  freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_sga freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)      

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD2b.tex, $tab_options_out

restore


* Table D.3(a)
* ======================

preserve 

keep if lowsales == 1

collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF_lowsales "log(Markup)" 

est clear
qui eststo: reg lmarkup_PF_lowsales dur_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_lowsales dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)  
qui eststo: reg lmarkup_PF_lowsales freq_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_lowsales freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)      

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD3a.tex, $tab_options_out

restore


* Table D.3(b)
* ======================

preserve 

keep if excgro == 1

collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF_excgro "log(Markup)" 

est clear
qui eststo: reg lmarkup_PF_excgro dur_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_excgro dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)  
qui eststo: reg lmarkup_PF_excgro freq_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_excgro freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)      

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD3b.tex, $tab_options_out

restore


* Table D.3(c)
* ======================

preserve 

keep if baseline == 1

collapse (mean) freq_avg3 dur_avg3 lmarkup_* naicsq2 naicsq4 liq lev latq, by(id)

* Labels
label var lmarkup_PF_tr1 "log(Markup)" 


est clear
qui eststo: reg lmarkup_PF_tr1 dur_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_tr1 dur_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)  
qui eststo: reg lmarkup_PF_tr1 freq_avg3 i.naicsq2 , vce(cluster naicsq4)     
qui eststo: reg lmarkup_PF_tr1 freq_avg3 i.naicsq2 latq lev liq, vce(cluster naicsq4)      

esttab *, $tab_options_disp

esttab using ${dirOutput}/TableD3c.tex, $tab_options_out

restore
